

'''
    需求:处理接口注册、登录、发帖、查询所有博文、删除博文(post类型)
         修改博文(put)、查询所有博文、批量查询博文(不分用户)（get类型）（下期实现）
         增加get方法请求

'''



import  requests
import hashlib
import pickle
import re
import time
from server_info import register,login,create,getBlogsOfUser,delete,getBlogContent,getBlogsContent,update
from Util import *





#testcase_path= 'data.txt'
#log_path= 'log.log'

count=1
result2= []
for line in get_testcase_data(test_data_path):
    temp= []
    #print(8, count, line)
    #if count==5:break
    line= pre_handle_data(line)
    #print(1,line)
    #print(9, count, line)
    url,test_data,http_method,assert_word,correlate_exp= line.split('||')
    url=eval(url)
    print(1,url,test_data,http_method,assert_word)
    start_time= time.time()
    req= send_request(url,test_data,http_method)
    end_time= time.time()
    #print(9,req,req.text)
    post_handle_data(correlate_exp,req.text)
    print(global_data)
    elapse_time= round(end_time-start_time)
    result= assert_result(req.text,assert_word)
    #count+=1
    #if count==2:breakr
    count += 1
    write_log(log_path,url,http_method,test_data,req.text,elapse_time,result,assert_word)
    print('*'*30)

    temp.append(url)
    temp.append(test_data)
    temp.append(req.text)
    temp.append(assert_word)
    temp.append(elapse_time)
    temp.append(result)
    result2.append(temp)

from test_outputhtml5 import report_html
html_name = '接口测试报告' + str(time.time())
report_html(result2,html_name)
